use super::get;
use super::Responder;
use crate::model::{AreaDto, TraitIndex};
use crate::model::User;
use crate::{model, RB};
use actix_web::web::Path;
use log::info;
use rbatis::impled;
use rbatis::html_sql;

#[get("/query_first")]
pub async fn query_first() -> impl Responder {
    model::JsonResult(User::select_by_id(&mut RB.clone(), 2).await)
}

#[get("/query_trait/{id}")]
pub async fn query_trait(path_info: actix_web::web::Path<i32>) -> impl Responder {
    info!("{}", path_info);
    model::JsonResult(TraitIndex::select_by_id(&mut RB.clone(), path_info.into_inner()).await)
}

#[get("/query_trait_code/{code}")]
pub async fn query_trait_code(path_info: actix_web::web::Path<String>) -> impl Responder {
    info!("{}", path_info);
    model::JsonResult(TraitIndex::select_by_code(&mut RB.clone(), (path_info.into_inner()+"%").as_str()).await)
}

#[html_sql("mapper/user.html")]
pub async fn select_by_condition(
    rb: &mut dyn rbatis::executor::Executor,
    code: &str,
    code_len: i32,
) -> Vec<AreaDto> {
    impled!()
}